# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _


class MrpProduction(models.Model):
    _inherit = 'mrp.production'

    def s_action_subcontracting(self):
        form_id = self.env.ref('sb_subcontracting.s_mrp_workorder_backorder_wizard_form_view').id
        context = dict(self._context)
        context['default_production_id'] = self.id
        # context['default_line_ids'] = [(0, 0, {'workorder_id': w.id}) for w in self.workorder_ids.filtered(lambda x: x.state!='done')]
        action = {
            'name': _('Workorder Subcontracting'),
            'view_mode': 'form',
            'view_type': 'form',
            'res_model': 's.mrp.workorder.backorder.wizard',
            'target': 'new',
            'views': [(form_id, 'form')],
            'type': 'ir.actions.act_window',
            'context': context,
        }
        return action
